home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / C for beginners.adf / source / math2.c < prev    next >
C/C++ Source or Header  |  1978-01-17  |  902b  |  83 lines

  1. /* math2.c 4.5.4 */
  2. void main()
  3. {
  4.   float number1, number2, result;
  5.   int operator, error;
  6.  
  7.   printf("Please input two numbers!\n");
  8.   scanf("%f%f", &number1, &number2);
  9.   printf("And now the code for the operation!\n");
  10.   printf("1=Add, 2=Subtract, 3=Multiply, 4=Divide\n");
  11.   scanf("%d", &operator);
  12.   error = 1;
  13.   if(operator == 1) /* Addition */
  14.     {
  15.      result = number1 + number2;
  16.      error = 0;
  17.     }
  18.   if(operator == 2) /* Subtraction */
  19.     {
  20.      result = number1 - number2;
  21.      error = 0;
  22.     }
  23.   if(operator == 3) /* Multiplication */
  24.     {
  25.      result = number1 * number2;
  26.      error = 0;
  27.     }
  28.   if(operator == 4) /* Division */
  29.     {
  30.      result = number1 / number2;
  31.      error = 0;
  32.     }
  33.   if(error == 1) /* None of the above conditions  */
  34.   printf("Wrong Code! Input only codes 1-4!\n");
  35. else
  36.   printf("The result is %f\n", result);
  37. }
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.